﻿using System.Runtime.Serialization;
using Foundation;
using Poet.Modules;

namespace Poet.ViewModels
{
    [DataContract]
    internal class FormatSetViewModel : DocumentSettingsViewModel<FormatSet>
    {
        public FormatSetViewModel()
        {
            Initialize();
        }

        protected override sealed FormatSet GetFactorySettings()
        {
            return
                new FormatSet
                    {
                        Name = "Factory",
                        ShowLineNumbers = true,
                        ShowTabs = false,
                        ShowBoxeForControlCharacters = false,
                        ShowEndOfLines = false,
                        BracketComplete = true,
                        ShowSpaces = false,
                        SpellCheck = true,
                        SyntaxHightlight = false,
                        TextFolding = false,
                        WordComplete = false,
                        WordWrap = false,
                        HideCurrentLineWhenTextSelected = true,
                    };
        }

        [OnDeserialized]
        private void Initialize(StreamingContext context = default(StreamingContext))
        {
            ApplicationClosing += () => this.TrySerializeDataContract();
            GetSettingsAction += model => model.GetCommon();
            SetSettingsAction += (model, common) => model.SetCommon(common);
        }
    }
}
